package com.yuyue.dronesystem.components;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;


/**
 * MyLocaleResolver
 */
public class MyLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String l = request.getParameter("l");
        String[] split = request.getHeader("Accept-Language").split(",")[0].split("-");
        Locale locale = new Locale(split[0],split[1]);
        if (!StringUtils.isEmpty(l)) {
            split = l.split("_");
            locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    }
}